
local vars creativityt numeracyt readingt 

* reverse coded raw scores
foreach v of local vars {
	ge `v'_r_7=6-`v'_7
}


* Standarized reverse coded raw scores
foreach v of local vars {
	egen `v'_rsd_7=std(`v'_r_7)
}

* percentile scores and standardized percentile scores
foreach v of local vars {

	ge `v'_p_7 = .
	replace `v'_p_7 = .025 if `v'_7==5
	replace `v'_p_7 = .175 if `v'_7==4
	replace `v'_p_7 = .5   if `v'_7==3
	replace `v'_p_7 = .825 if `v'_7==2
	replace `v'_p_7 = .975 if `v'_7==1

	egen `v'_psd_7= std(`v'_p_7)

}

* Binary measure of creativity
ge Bcreativityt_psd_7=creativityt_psd_7>0
replace Bcreativityt_psd_7=. if creativityt_psd_7==.

* percentiles of math and reading scores at age 7
local vars math reading 
foreach v of local vars {
	sort `v'_7
	ge nn=_n

	bys `v'_7: egen max_nn=max(nn)
	bys `v'_7: egen min_nn=min(nn)
	qui su nn
	ge r_max_nn=max_nn/r(N)
	ge r_min_nn=min_nn/r(N)

	ge pr_`v'_7 = 0.025 if r_min_nn<0.05
	replace pr_`v'_7 = 0.175 if r_min_nn>=0.05 & r_min_nn<.3
	replace pr_`v'_7 = 0.825 if r_max_nn>.7 & r_max_nn<=.95
	replace pr_`v'_7 = 0.975 if r_max_nn>.95
	replace pr_`v'_7=0.5 if pr_`v'_7==.

	drop nn max_nn min_nn r_max_nn r_min_nn

}

corr numeracyt_p_7 pr_math_7
corr readingt_p_7 pr_reading_7

ge tbm_7=numeracyt_p_7-pr_math_7
ge tbr_7=readingt_p_7-pr_reading_7

** average bais in math and reading
ge tb_7=(tbm_7+tbr_7)/2
label variable tb_7 "Teacher evaluation error (age 7)"

** teachers average skill rating
ge tevalmr = (numeracyt_p_7 + readingt_p_7)/2
label variable tevalmr "Teacher evaluation of cognitive ability"

* Percentile creativity based on empirical percentile of reverse coded raw scores
ge creativityt_ep_7 = .
forvalues j=1/5{

	ge ii= creativityt_r_7==`j'
	su ii
	local p=r(mean)/2

	ge jj= creativityt_r_7<`j'
	su jj
	local p0=r(mean)

	replace creativityt_ep_7=`p'+`p0' if creativityt_r_7==`j'

	drop ii jj

}
egen creativityt_epsd_7= std(creativityt_ep_7)

